var PeopleMedia = PeopleMedia || {};
PeopleMedia.NewMembersInArea = new function () {
	
	var lastToggle = null;
	var lastIndex = null;
	this.FeatureName = 'newmembers';
    this.toggleFavorite = function (addToFavs, encryptedMemberId, index) {
        if (encryptedMemberId == null)
            return;

        if (lastToggle && lastToggle.getTime() > ((new Date()).getTime() - 1000))
            return;
        lastToggle = new Date();
        lastIndex = index;
        var url = null;
        if (addToFavs) {
            $jq('#member' + index).mouseleave(function() { $jq(this).children(".staroverlayplace").show();});
            $jq('#member' + index).find("#staroverlayFavorite").show();
            $jq('#member' + index).find("#staroverlayNonFavorite").hide();
            url = PeopleMedia.Homepage.Actions.AddFavorite;
        } else {
            $jq('#member' + index).mouseleave(function() { $jq(this).children(".staroverlayplace").hide();});
            $jq('#member' + index).find("#staroverlayFavorite").hide();
            $jq('#member' + index).find("#staroverlayNonFavorite").show();
            url = PeopleMedia.Homepage.Actions.UnFavorite;
        }
        $jq.ajax({
            type: 'POST',
            dataType: "json",
            url: url,  
            data: {
                EncodedMemberId: encryptedMemberId,
                FeatureName: PeopleMedia.NewMembersInArea.FeatureName
            },
            success: function (response) {
                if (response.status == "Success") {
                   $jq('#member' + index).attr('data-favorite','True');
                } else {
                    PeopleMedia.Connect.handleError(response);
                }
            },
        });
    };




	this.init =  function() {

		$jq(".newmemberrepeat").mouseover(function() { $jq(this).children(".staroverlayplace").show();});
		$jq(".newmemberrepeat").mouseleave(function() { 
			var favorite = $jq(this).attr("data-favorite");

			if (favorite == 'True')
			{
					 $jq(this).children(".staroverlayplace").show();
			}
			else
			{
					 $jq(this).children(".staroverlayplace").hide();
			}

	
		});
	};

	 $jq(document).ready(function () {
        PeopleMedia.NewMembersInArea.init();
    });
};
                              
